package com.johnny.xia.util.sap;

import com.johnny.xia.util.base.RandUtil;
import com.johnny.xia.util.date.DateUtil;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName OrderSap
 * @Author johnny xia
 * @mailto johnny.xia@qq.com
 * @Date 2021/9/15 12:31 下午
 * @Description TODO
 **/
public class OrderSap {

  public static void main(String[] args) {

    String shop = "CH";
    String storeCode = shop.equals("CH") ? "880040140I01" : "2107209606";
    String orderCode = shop.equals("CH")?"CH"+DateUtil.date2Str(new Date(),"yyyyMMddHHmmss"):"DU"+DateUtil.date2Str(new Date(),"yyyyMMddHHmmss");
    String ownerCode=shop.equals("CH") ? "880040140I01" : "2107209606";
    String platformOrderCode= DateUtil.date2Str(new Date(),"yyyyMMddHHmmss")+ RandUtil.RandInt(1,10000);
    int totalQty = 0;
    BigDecimal totalAmount = BigDecimal.ZERO;
    BigDecimal discountAmount =BigDecimal.ZERO;
    BigDecimal transFee = BigDecimal.ZERO;

    OutboundOrder outboundOrder = new OutboundOrder();
    outboundOrder.setOrderCode(orderCode);
    outboundOrder.setPlatformOrderCode(platformOrderCode);
    outboundOrder.setStoreCode(storeCode);

    List<SkuInfo> skus = skus(shop);
    for(int i=0;i< skus.size();i++) {
      int qty = 1;
      int lineNo = (i + 1) * 10;
      SkuInfo sku = skus.get(i);
      OutBoundLine line = OutBoundLine.builder()
          .lineNo(String.valueOf(lineNo))
          .storeCode(storeCode)
          .skuCode(sku.getSkuCode()+(shop.equals("CH")?"_P_100000572":"_P_100000630"))
          .extCode(sku.getSkuCode())
          .upc(sku.getSkuCode())
          .barCode(sku.getSkuCode())
          .color(sku.getColor())
          .size(sku.getSize())
          .style(sku.getStyle())
          .skuName(sku.getSkuName())
          .listPrice(sku.getPrice())
          .unitPrice(sku.getPrice())
          .actualPrice(sku.getPrice())
          .qty(1)
          .lineAmt(sku.price.multiply(new BigDecimal(qty)))
          .ownerCode(ownerCode)
          .invStatus(1)
          .build();

      totalQty += qty;
      totalAmount = totalAmount.add(line.getLineAmt());
      outboundOrder.getOutBoundLine().add(line);
    }

    outboundOrder.setTotalAmount(totalAmount);
    outboundOrder.setQty(totalQty);
    outboundOrder.setDiscountAmount(discountAmount);
    outboundOrder.setTransFee(transFee);


    Receiver receiver = new Receiver();
    receiver.setName("夏龙");
    receiver.setMoblie("18701891994");
    outboundOrder.setReceiver(receiver);

    Sender sender = new Sender();
    outboundOrder.setSender(sender);

    XmlInterfaceUtils.convertToXml(outboundOrder);

  }

  private static List<SkuInfo> skus(String shop){

    List<SkuInfo> skus = new ArrayList<>();
    if("CH".equals(skus)){
      SkuInfo sku1 = SkuInfo.builder().style("CHC21AT090MDC").skuCode("CHC21AT090MDC9CA").skuName("莫代尔拼接围巾").color("Multicolour").price(new BigDecimal("2800")).size("均码").build();
      SkuInfo sku2 = SkuInfo.builder().style("CHC21AS605F01").skuCode("CHC21AS605F01053").skuName("MARCIE马鞍包").color("Cashmere grey").price(new BigDecimal("11700")).size("均码").build();
      SkuInfo sku3 = SkuInfo.builder().style("CHC21ADP82151").skuCode("CHC21ADP8215146834").skuName("靴型牛仔裤").color(" Grizzled Blue").price(new BigDecimal("6190")).size("34").build();
      skus.add(sku1);
      skus.add(sku2);
      skus.add(sku3);
    }else{
      SkuInfo sku1 = SkuInfo.builder().style("CHC21AT090MDC").skuCode("CHC21AT090MDC9CA").skuName("莫代尔拼接围巾").color("Multicolour").price(new BigDecimal("5777")).size("均码").build();
      SkuInfo sku2 = SkuInfo.builder().style("CHC21AS605F01").skuCode("CHC21AS605F01053").skuName("MARCIE马鞍包").color("Cashmere grey").price(new BigDecimal("5777")).size("均码").build();
      SkuInfo sku3 = SkuInfo.builder().style("CHC21ADP82151").skuCode("CHC21ADP8215146834").skuName("靴型牛仔裤").color(" Grizzled Blue").price(new BigDecimal("10000")).size("34").build();
      skus.add(sku1);
      skus.add(sku2);
      skus.add(sku3);
    }
    return skus;
  }
}
